package com.example.hospital.service;

import com.example.hospital.common.PageResponse;
import com.example.hospital.domain.dto.StatusCount;
import com.example.hospital.domain.entity.Sample;
import com.example.hospital.mapper.SampleMapper;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SampleService {
    private final SampleMapper sampleMapper;

    public SampleService(SampleMapper sampleMapper) {
        this.sampleMapper = sampleMapper;
    }
    /**
     * 创建样本
     * @param sample
     * @return
     */
    public Sample create(Sample sample) {
        sampleMapper.insert(sample);
        return sampleMapper.findById(sample.getSampleId());
    }
    /**
     * 更新样本状态
     * @param sampleId
     * @param status
     * @param remark
     * @return
     */
    public boolean updateStatus(Long sampleId, Integer status, String remark) { return sampleMapper.updateStatus(sampleId, status, remark) > 0; }
    /**
     * 获取样本列表
     * @param sampleId
     * @param orderId
     * @param sampleType
     * @param status
     * @param page
     * @param size
     * @return
     */
    public PageResponse<Sample> list(Long sampleId, Long orderId, String sampleType, Integer status, int page, int size) {
        int offset = (page - 1) * size;
        List<Sample> list = sampleMapper.list(sampleId, orderId, sampleType, status, size, offset);
        long total = sampleMapper.count(sampleId, orderId, sampleType, status);
        return PageResponse.of(total, page, size, list);
    }
    /**
     * 获取样本状态统计
     * @return
     */
    public List<StatusCount> stats() {
        return sampleMapper.stats();
    }
}